<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@include file="common/indexhead.jsp"%>
<%@include file="common/tag.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/mystyle/zTreeStyle/css/demo.css"
	type="text/css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/mystyle/zTreeStyle/css/zTreeStyle.css"
	type="text/css">
<script
	src="${pageContext.request.contextPath}/assets/vendor/jquery/jquery.min.js"></script>
<script
	src="${pageContext.request.contextPath}/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/mystyle/zTreeStyle/js/jquery.ztree.core.js"></script>
<script src="${pageContext.request.contextPath}/mystyle/js/userclick.js"
	type="text/javascript" charset="utf-8"></script>
<!-- <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> -->

</head>

<body>
<table class="table table-hover">
			<thead>
				<tr>
					<th>用户名</th>
					<th>用户编号</th>
					<th>职&nbsp;&nbsp;务</th>
					<!-- <th>毕业院校</th> -->
					<th>联系电话</th>
					<th>创建时间</th>
					<th>详情</th>
					<th class="mydelete">删除</th>
					</tr>
			</thead>
			<tbody>
				<c:forEach var="us" items="${userlist}">
					<tr>
						<td>${us.userName}</td>
						<td>${us.userNumber}</td>
						<td>${us.userJob}</td>
						<%-- <td>${us.userSchool}</td> --%>
						<td>${us.userTel}</td>
						<td><fmt:formatDate value="${us.createTime}" pattern="yyyy-MM-dd"/></td>
						<td style="width:10px"><a class="btn btn-info"  href="/user/${us.userId}/detail"  target="_blank">详情</a></td>
						<td class="mydelete" style="width:10px"><a class="btn btn-danger" onclick="tijiao('${us.userId}')">删除</a></td>
					</tr>
				</c:forEach>  
				<%-- onclick="window.parent.changeIframe('/user/${us.userId}/detail')"   --%>
			</tbody>
		</table>
		<div style="margin-top: -30px;" id="resultlist" >
	
		</div>
	<!-- 弹出框重写 -->
<div id="ycf-alert" class="modal">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
            <h5 class="modal-title"><i class="fa fa-exclamation-circle"></i> [Title]</h5>
          </div>
          <div class="modal-body small">
            <p>[Message]</p>
          </div>
          <div class="modal-footer" >
            <button type="button" class="btn btn-primary ok" data-dismiss="modal">[BtnOk]</button>
            <button type="button" class="btn btn-default cancel" data-dismiss="modal">[BtnCancel]</button>
          </div>
        </div>
      </div>
    </div>
<!-- 弹出框重写end -->
</body>
<script type="text/javascript">

fenye(${pb.currentPage},${pb.totalPages},${pb.totalRecords},${pb.pagesize},"/user/userlist");
</script>
<script type="text/javascript">
/*  Modal.confirm(
{
    msg: "是否删除角色？"
}) 
Modal.alert(
            {
                msg: res['msg'],
                title: '操作',
                btnok: '确定',
                btncl:'取消'
            });*/
$(function() {
if("<%=request.getSession().getAttribute("userid")%>"!="admin"){
	$(".mydelete").hide();
}
window.Modal = function() {
    var reg = new RegExp("\\[([^\\[\\]]*?)\\]", 'igm');
    var alr = $("#ycf-alert");
    var ahtml = alr.html();

    //关闭时恢复 modal html 原样，供下次调用时 replace 用
    //var _init = function () {
    //alr.on("hidden.bs.modal", function (e) {
    //  $(this).html(ahtml);
    //});
    //}();
    /* html 复原不在 _init() 里面做了，重复调用时会有问题，直接在 _alert/_confirm 里面做 */

    var _alert = function(options) {
        alr.html(ahtml); // 复原
        alr.find('.ok').removeClass('btn-success').addClass('btn-primary');
        alr.find('.cancel').hide();
        _dialog(options);

        return {
            on: function(callback) {
                if (callback && callback instanceof Function) {
                    alr.find('.ok').click(function() {
                        callback(true)
                    });
                }
            }
        };
    };

    var _confirm = function(options) {
        alr.html(ahtml); // 复原
        alr.find('.ok').removeClass('btn-primary').addClass('btn-success');
        alr.find('.cancel').show();
        _dialog(options);

        return {
            on: function(callback) {
                if (callback && callback instanceof Function) {
                    alr.find('.ok').click(function() {
                        callback(true)
                    });

                }
            }
        };
    };

    var _dialog = function(options) {
        var ops = {
            msg: "提示内容",
            title: "操作提示",
            btnok: "确定",
            btncl: "取消"
        };

        $.extend(ops, options);

        console.log(alr);

        var html = alr.html().replace(reg,
        function(node, key) {
            return {
                Title: ops.title,
                Message: ops.msg,
                BtnOk: ops.btnok,
                BtnCancel: ops.btncl
            } [key];
        });

        alr.html(html);
        alr.modal({
            width: 500,
            backdrop: 'static'
        });
    }

    return {
        alert: _alert,
        confirm: _confirm
    }

} ();
});

function tijiao(userId) {
Modal.confirm({
    msg: "是否删除该用户？"
}).on(function(e) {
    $.ajax({
        type: "get",
        url: yongan.URL.userDelete(userId),
        dataType: "json",
        data: {},
        success: function(data) {

            if (data['success']) {
                Modal.alert({
                    msg: data['data']['stateinfo'],
                    title: '执行结果',
                    btnok: '确定',
                    btncl: '取消'
                }).on(function(e) {
                    window.location.reload();
                });
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
            alert(textStatus);
            alert(errorThrown);
        }
    });
});
}




</script>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/mystyle/dialog/jquery-ui-1.10.4.custom.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/mystyle/dialog/jquery-ui-1.10.4.custom.min.css">
	<script src="${pageContext.request.contextPath}/mystyle/dialog/jquery-ui-1.10.4.custom.js"></script>
	<script src="${pageContext.request.contextPath}/mystyle/dialog/jquery-ui-1.10.4.custom.min.js"></script>
</html>
